/*
 *  Class name: StatusInfoInterceptor.java
 *  Version: 1.0
 *  Date: 23.6.2014
 */

package cz.morosystems.personwebmanager.presentationlayer.interceptors;

import cz.morosystems.personwebmanager.businesslayer.sevices.UserService;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 *
 * @author Michal Ďuriš
 */
@Component
public class StatusInfoInterceptor extends HandlerInterceptorAdapter {

    @Autowired
    private UserService userService;
    
    public StatusInfoInterceptor() {
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object handler)
            throws Exception {
        
        request.setAttribute("userCount", userService.getAllUsers().size());
        request.setAttribute("currentTime", new Date());
        
        return true;
    }

    
    
    
}
